/*******************************************************************************
 * Copyright (c) 2011 Jovansonlee B. Cesar.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *     Jovansonlee B. Cesar - initial API and implementation
 ******************************************************************************/
package com.ivanceras.shared.db;

import com.ivanceras.shared.exception.DatabaseException;



public interface IDatabase{
	
	public void beginTransaction() throws DatabaseException;
	public void commitTransaction() throws DatabaseException;
	public void rollbackTransaction() throws DatabaseException;
	public boolean isTransacted() throws DatabaseException;
	
	DAO[] select(ModelDef model, Join join, Filter[] filters, Integer offset, Integer limit, Boolean doCount, Order[] orders) throws DatabaseException;

	boolean createModel(ModelDef model) throws DatabaseException;
	
	DAO insert(DAO dao, ModelDef model) throws DatabaseException;
	
	DAO update(DAO dao, ModelDef model, Filter[] filters) throws DatabaseException;
	
	int delete(ModelDef model, Filter[] filters) throws DatabaseException;
	
	int empty(ModelDef model) throws DatabaseException;
	
	boolean drop(ModelDef model) throws DatabaseException;

	boolean isClosed(); 

	
	/**
	 * This method is called when a connection is to be reused - it should ensure that there are no transactions pending 
	 * (it should rollback if there is), and do any other required housecleaning if needed, so the connection can be re-used.
	 * @return
	 */
	boolean reset();
	Integer getTotalRecords(String schema, String modelName)
			throws DatabaseException;
	ModelDef getModelMetaData(String schema, String tableName) throws DatabaseException;
//	ResultSet executeSelectSQL(String sql, Object[] parameters)
//			throws DatabaseException;
	SchemaTable[] getTableNames(String schema, String tablePattern)
			throws DatabaseException;


}
